import {
	judgeChief,
	getBackgroundImageList,
	addBackgroundImage,
	saveBackgroundImage,
	delBackgroundImage,
	getOtherWorkStatus,
	saveOtherWorkStatus,
	getAllBizScenario,
	getAllGroupSkill,
	getBizscenariosInfo,
	fetchTTSTalks,
	fetchBusinessMaterial,
	fetchAgentListWithBizscenarioId,
	updateAudioVideoCallIsConnectedStatus,
	getHumanflowById,
	getSessionSummaryList,
} from '@/api';

export const validateChiefLoginSystem = async (userId: number | string, groupId: number | string) => {
	try {
		const { data } = await judgeChief(userId, groupId);
		return data ? { isTeamLeader: true, groupId: groupId } : { isTeamLeader: false, groupId: groupId };
	} catch (error) {
		console.log(error, 'validateChiefLoginSystem error');
		return { isTeamLeader: false, groupId: groupId };
	}
};

export const getBackgroundList = async (data: { page: number; pageSzie: number }) => {
	const { page = 1, pageSzie = 10 } = data;
	return await getBackgroundImageList(page, pageSzie);
};

export const createBackgroundImage = async (data: { url: string; abbreviatedUrl: string; fileName: string; isDefault: boolean; type: 'no' | 'normal' | 'fuzzy' }) => {
	return await addBackgroundImage(data);
};

export const applyBackgroundImage = async (data: { backgroundId: number }) => {
	return await saveBackgroundImage(data);
};

export const deleteBackgroundImage = async (id: number) => {
	return await delBackgroundImage(id);
};

export const checkedAgentOtherWork = async () => {
	return await getOtherWorkStatus();
};

export const saveOtherWork = async (data: { sessionOver: boolean; timeoutOver: boolean; reasonForSessionOver: string; reasonForTimeoutOver: string }) => {
	return await saveOtherWorkStatus(data);
};

//获取当前机构下的所有分组
export const getAllGroupsWithOrg = async () => {
	return await getAllBizScenario();
};

//获取当前机构下的所有分组
export const fetchGroupSkill = async () => {
	return await getAllGroupSkill();
};

export const fetchGroupWithBizscenariosID = async (id: number) => {
	return await getBizscenariosInfo(id);
};

/**
 * 分页获取 tts 话术
 * @param params
 * @returns
 */
export const fetchTTSTalksWithPageSize = async (params: { scenId: string | number; page: number; pageSize: number }) => {
	return await fetchTTSTalks(params);
};

/**
 * 分页获取业务场景资料
 * @param params
 * @returns
 */
export const fetchBusinessMaterialWithPageSize = async (params: { scenId: string | number; type: 'document' | 'video'; page: number; pageSize: number }) => {
	return await fetchBusinessMaterial(params);
};

/**
 * 分页获取坐席列表
 * @param params
 * @returns
 */
export const fetchScenAgentList = async (scenId: string) => {
	return await fetchAgentListWithBizscenarioId(scenId);
};

/**
 * 更新会话是否接通状态
 * @param params
 * @returns
 */
export const updateMediaRenderStatus = async (sessionId: string, audioVideoCallIsConnected: boolean) => {
	return await updateAudioVideoCallIsConnectedStatus(sessionId, audioVideoCallIsConnected);
};

/**
 * 获取人工工作流详情
 * @param id 
 * @returns 
 */
export const fetchHumanflowById = async (id: string) => {
	return await getHumanflowById(id);
};

/**
 * 获取会话小结配置
 * @returns 
 */
export const fetchSessionSummaryList = async (scenId: string) => {
	return await getSessionSummaryList(scenId);
};

